//
//  GYRefundDetailsViewController.m
//  GoodLuck
//
//  Created by 郭为勇 on 2018/3/25.
//  Copyright © 2018年 yunjiazhineng. All rights reserved.
//

static NSString *refunDetailsCellIdentifier = @"refunDetailsCellIdentifier";
#import "GYRefundDetailsViewController.h"
#import "GYNetWorkTools.h"

@interface GYRefundDetailsViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableview;

/** 标题 */
@property (nonatomic, strong) NSArray *titles;

/** 内容 */
@property (nonatomic, strong) NSArray *contents;

@end

@implementation GYRefundDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //初始化
    [self setupUI];
}

- (void)setupUI {
    self.navigationItem.title = @"退款详情";
    self.tableview.rowHeight = 50;
    self.tableview.sectionHeaderHeight = 50;
    self.tableview.sectionFooterHeight = 0;
    self.tableview.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, CGFLOAT_MIN)];
    self.tableview.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, CGFLOAT_MIN)];
    
    //只有这个状态下数据才能删除
    if ([self.refundModel.refund_state intValue] == 3) {
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"删除" style:UIBarButtonItemStylePlain target:self action:@selector(deleteRefundList)];
        
    }
}

- (void)deleteRefundList {
        [GYNetWorkTools requestDeleteRefundOrder:self.refundModel.refund_id success:^(NSDictionary *obj) {
            NSLog(@"obj=============%@",obj);
            int code = [[obj objectForKey:@"code"] intValue];
            if (code == 200) {
                [EasyTextView showSuccessText:@"删除订单成功!"];
                [self.navigationController popViewControllerAnimated:YES];
            }else if (code == 400) {
                NSDictionary *datas = [obj objectForKey:@"datas"];
                NSString *error = [datas objectForKey:@"error"];
                [EasyTextView showErrorText:error];
            }
        } error:^(NSError *error) {
            NSLog(@"error=========%@",error);
        }];
}

#pragma  mark -- UITableViewDelegate,UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.titles.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.titles[section] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:refunDetailsCellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:refunDetailsCellIdentifier];
    }
    
    cell.textLabel.text = self.titles[indexPath.section][indexPath.row];
    cell.textLabel.font = [UIFont systemFontOfSize:16];
    cell.textLabel.textColor = RGBColor(57, 58, 60);
    cell.detailTextLabel.text = self.contents[indexPath.section][indexPath.row];
    cell.detailTextLabel.font = [UIFont systemFontOfSize:14];
    cell.detailTextLabel.textColor = RGBColor(57, 58, 60);
    
    return cell;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 50)];
    bgView.backgroundColor = [UIColor clearColor];
    UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, ScreenWidth, 50)];
    lable.font = [UIFont systemFontOfSize:16];
    lable.backgroundColor = [UIColor clearColor];
    if (section == 0) {
        lable.text = @"我的退款申请";
    }else {
        lable.text = @"商家退款处理";
    }
    [bgView addSubview:lable];
    
    return bgView;
}

#pragma mark -- 懒加载

- (NSArray *)titles {
    if (!_titles) {
        _titles = @[@[@"退款编号",@"退款原因",@"退款金额",@"退款说明",@"凭证上传"],@[@"审核状态",@"商家备注"]];
    }
    
    return _titles;
}

- (NSArray *)contents {
    if (!_contents) {
        _contents = @[
                      @[self.refundModel.refund_sn == nil ? @"dsa" : self.refundModel.refund_sn,
                        self.refundModel.reason_info == nil ? @"das" : self.refundModel.reason_info,
                        self.refundModel.refund_amount == nil ? @"das" : self.refundModel.refund_amount,
                        self.refundModel.buyer_message == nil ? @"da" : self.refundModel.buyer_message,
                        self.refundModel.pic_info == nil ? @"dsa" : self.refundModel.pic_info],
                      @[self.refundModel.seller_state == nil ? @"da" : self.refundModel.seller_state,
                        self.refundModel.seller_message == nil ? @"das" : self.refundModel.seller_message
                        ]
                      ];
    }
    
    return _contents;
}

@end
